AnnieRoot.gtip=AnnieRoot.gtip||{};
gtip.ChooesPrizeBox=function(){
	var s = this;
	annie.MovieClip.call(s);
	/*_a2x_need_start*/s.chooesListCon=null;s.close_btn=null;s.marksure_btn=null;s.prizeListCon=null;/*_a2x_need_end*/
	annie.initRes(s,"gtip","ChooesPrizeBox");
	//your code here
	s.addEventListener(annie.Event.ADD_TO_STAGE, function (e) {
		if (gameGlobalData.chooesGiftData) {
			var prizesLen = gameGlobalData.chooesGiftData.length;
			s.prizeListArr = [];
			s.prizeListCon.removeAllChildren();
			for (var i = 0; i < prizesLen; i++) {
				var prizeListModel = new gtip.PrizeModel();
				var pname = gameGlobalData.surplusGiftData[parseInt(gameGlobalData.chooesGiftData[i]) - 1].name;
				var psum = gameGlobalData.surplusGiftData[parseInt(gameGlobalData.chooesGiftData[i]) - 1].sum;
				prizeListModel.prize_txt.text = pname + '   X   1' + '(剩余数量:' + psum + ')';
				prizeListModel.prizeId = gameGlobalData.chooesGiftData[i];
				prizeListModel.ids = i;
				prizeListModel.y = i * 54;
				s.prizeListArr[i] = prizeListModel;
				s.prizeListCon.addChild(prizeListModel);
				prizeListModel.addEventListener(annie.MouseEvent.CLICK, function (e) {
					var plModel = e.currentTarget;
					// trace('ids:' + plModel.ids);
					s.updateBtnStatus(prizesLen, plModel.ids);//
				})
			}
			s.updateBtnStatus(prizesLen, 0);//默认第一个选中
		} else {
			trace('无可选择数据！');
		}
	})
	s.close_btn.addEventListener(annie.MouseEvent.CLICK, function (e) {
		annie.globalDispatcher.dispatchEvent('addWarmTipBox');//提示确认页
	})
	/*提交用户选择的奖品*/
	s.marksure_btn.addEventListener(annie.MouseEvent.CLICK, function (e) {
		ServerMessageManager.postUserChooesPrize(s.currUserChooesPrizeId, function (result) {
			if (result.status == 1) {
				if (result.data) {
					annie.globalDispatcher.dispatchEvent('addMarkSureTipBox', result.data);//选择奖品成功，提示页
				} else {
				}
			} else {
				trace('sorry!' + result.data);
			}
		})
	})
};
A2xExtend(gtip.ChooesPrizeBox,annie.MovieClip);
gtip.ChooesPrizeBox.prototype.updateBtnStatus = function (btnLen, targetBtnId) {
	var s = this;
	for (var i = 0; i < btnLen; i++) {
		if (s.prizeListArr[i].ids == targetBtnId) {
			s.prizeListArr[targetBtnId].tick_mc.gotoAndPlay(2);
			s.currUserChooesPrizeId = s.prizeListArr[i].prizeId;
		} else {
			s.prizeListArr[i].tick_mc.gotoAndStop(1);
		}
	}
}
